﻿using NPinyin;

namespace DNFImagePacks2Manager.Models
{
    public abstract class PinYinItem
    {
        private string _name = string.Empty;

        private string? _pinyin;

        public string Name
        {
            get => _name;
            set
            {
                _name = value;
                _pinyin = null;
            }
        }

        public string PinYinName
        {
            get
            {
                if (_pinyin == null)
                {
                    UpdatePinYinName();
                }
                return _pinyin ?? Name;
            }
        }

        public void UpdatePinYinName()
        {
            _pinyin = Pinyin.GetPinyin(Name).Replace(" ", string.Empty).ToLowerInvariant();
        }
    }
}
